<?php 
namespace app\Home\controller;
use think\Controller;
use think\Request;
use think\Session;
use think\Db;
class Login extends Controller
{
	public function login(){
		return $this->fetch();
	}
	public function login_do(){
		$username=Request::instance()->post("username");
        $password=Request::instance()->post("password");
        $res = Db::table('login')->where("username='$username'")->select();
        // print_r($res);die;
		if($res){
            // print_r($res[0]['password']);die;
            if($res[0]['password']== md5($password)) {

                $remember = Request::instance()->post("remember");
                // var_dump($remember);die;
                if(!empty($remember)){
                Session::set("id",$res[0]['id'],3600*12*7);
                Session::set('username',$res[0]['username'],3600*12*7);
                $this->redirect('Index/index');
                }else{
                Session::set("id",$res[0]['id']);
                Session::set('username',$res[0]['username']);
                $this->redirect('Index/index');
                }
                // print_r($remember);die;
                
            }else{
                echo "<script>alert('密码错误');location.href='login'</script>";
            }
        }else{
            echo "<script>alert('用户名错误');location.href='login'</script>";
        }

	}


}